#ifndef COLLISIONSHAPESDOCUMENT_H
#define COLLISIONSHAPESDOCUMENT_H

#include <QObject>

class GraphicsObject;
class Animation;
class Texture;
class CollisionShape;
class QUndoStack;

class CollisionShapesDocument : public QObject
{
    Q_OBJECT
public:
    explicit CollisionShapesDocument(QObject *parent = 0);

    QPointer<CollisionShape> createRectShape(const QRectF &rect);
    QPointer<CollisionShape> createCircleShape(QPointF center, float radius);
    QPointer<CollisionShape> createPolyShape(const QPolygonF& poly);

    QPointer<GraphicsObject> graphicsObject() const { return m_gobject; }

    const QList<QPointer<CollisionShape> >& currentCollisionShapes() const;
    void currentGraphicsParameters(Texture **texture, QRect& rRect, bool& rIsAnimation);

    // selection methods
    const QList<QPointer<CollisionShape> >& selectedShapes() const;
    bool isSelected(QPointer<CollisionShape> shape) const;
    QPointer<CollisionShape> shapeUnderMouse(const QPointF& mousePos);

    void resetDocument();

    QPointer<QUndoStack> currentCSUndoStack();
    void addShape(QPointer<CollisionShape> shape);

    // manipulator methods
    float manipulatorSize() const { return m_fManipulatorSize; }
private:

    QPointer<GraphicsObject> m_gobject;
    QPointer<Animation> m_currentAnimation;
    int m_nCurrentFrame;

    QList<QPointer<CollisionShape> > m_selectedShapes;

    float m_fManipulatorSize;
signals:
    void editingObjectChanged();
    void shapeSelectionChanged();
    void shapeAdded(QPointer<CollisionShape> shape);
    void shapeRemoved(QPointer<CollisionShape> shape);
public slots:
    void setCurrentAnimation(QPointer<Animation> anim);
    void setCurrentFrame(int frameIndex);

    // selection methods
    void selectShape(QPointer<CollisionShape> shape);
    void deselectShape(QPointer<CollisionShape> shape);
    void selectAllShapes();
    void deselectAllShapes();

    void selectShape(const QPointF &pt);
    void selectShapes(const QRectF &area);

    // deletion
    bool deleteShape(QPointer<CollisionShape> shape);
    bool deleteSelection();

    // copy/paste
    void copySelectedShapes();
    void pasteShapes();
};

#endif // COLLISIONSHAPESDOCUMENT_H
